﻿using System;
using Besture.Bll;
using Besture.Common;
using Besture.Common.Helper;


namespace Besture.UI.Admin
{
    public partial class UpdatePassword : BasePage
    {
        /// <summary>
        /// 
        /// </summary>

        #region 页面加载事件

        /// <summary>
        /// 页面加载
        /// </summary>
        protected override void InitialLoad()
        {
            if (!IsPostBack)
            {
                lblUserName.Text = AdminUserService.AdminLoginUser.LoginName;
            }
        }

        /// <summary>
        /// 回发
        /// </summary>
        protected override void PostBackLoad()
        {

        }


        #endregion

        #region 保存

        protected void btnSubmit_Click(object sender, EventArgs eventArgs)
        {
            AdminUserDac dac = new AdminUserDac();
            string loginName = AdminUserService.AdminLoginUser.LoginName;
            string oldPassword =StringHelper.GetMD5(txtOldPassword.Text.Trim());
            string newPassword = StringHelper.GetMD5(txtNewPassword.Text.Trim());
            int itmp = dac.UpdatePassword(loginName, oldPassword, newPassword);
            switch (itmp)
            {
                case -1:
                    FunHelper.Alert("保存失败", "UpdatePassword.aspx");
                    break;
                case 1:
                    FunHelper.Alert("修改密码成功，请重新登录", "/Admin/Out.aspx");
                    break;
                case 2:
                    FunHelper.Alert("原密码不正确", "UpdatePassword.aspx");
                    break;
            }
        }
        #endregion

    }
}